package com.browsesoft.htmlcomponent;

import javax.servlet.http.HttpServletRequest;

import org.w3c.dom.Element;

import com.browsesoft.EntityManager;
import com.browsesoft.ExtendElement;
import com.browsesoft.user.User;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: Copyright (c) 2004
 * </p>
 * <p>
 * Company:
 * </p>
 * 
 * @author not attributable
 * @version 1.0
 */
public class UserShowComponent extends HTMLBasicComponent {
	public UserShowComponent(HTMLBasicComponent parent) throws Exception {
		super(parent);
	}

	/**
	 * 初始化时创建子组件并设置初始化参数
	 */
	public void init(HttpServletRequest request, Element e) throws Exception {
		super.init(request, e);
		String userID = request.getParameter("point");
		User user = (User) EntityManager.getInstance().getObject(userID);
		if (user != null) {
			user.getEName();
			user.getName();
			replaceElement("name", user.getName());
			replaceElement("ename", user.getEName());
		}
	}

	private Element getEle(String value) {
		return (Element) ExtendElement
				.findElements(this.element, "name", value).get(0);
	}

	private void replaceElement(String element, String value) {
		Element e = this.getEle(element);
		e.setAttribute("value", value);
	}
}